require(['./config'],() => {
	require(['swiper','template','request','bootstrap','header','footer'],(Swiper,template,req) => {
		class Index{
			constructor() {
			    // this.init()
				this.getIndexShow()
				this.getIndexData()
			}
			
			// 初始化swiper
			init(){
				var mySwiper = new Swiper('.swiper-container',{
				 direction : 'horizontal',
				 loop: true, // 循环模式选项
				 // autoplay:true;
				  pagination :{
					el: '.swiper-pagination',
					clickable :true,
				  },
				   // 如果需要前进后退按钮
					  navigation: {
						nextEl: '.swiper-button-next',
						prevEl: '.swiper-button-prev',
					  }
				})
				// console.log(mySwiper)		
				$('.swiper-pagination-bullet').mouseover(function(){
					this.click();
				})			
			}					
			// 请求首页商品展示
			getIndexShow(){				
				req.getIndexProdShow()
					.then(res => {
						if(res.code === 200){
							// const html = template('picShowTemplate',{list:res.result_body})
							$('.list').html(template('picShowTemplate',{list:res.result_body}))
						}
					})
			}	
			
			// 请求首页轮播图数据
			getIndexData(){
				// console.log(123)
				req.getIndexSwiperData()
					.then(res => {
						if(res.code === 200){
							// 渲染页面
							// console.log(res)
							const { banners} = res.data
							// console.log(banners)
							this.createIndexSwiper(banners)
							this.init()
						}
					})
			}
			
			// 渲染页面
			createIndexSwiper(res){
				console.log(res)
				// const [banners] = res
				// console.log(banners)
				$('.swiper-container').html(template('indexSwiperTemplate',{ res }))
			}
		}			
		return new Index()
	})
})